package com.bjx.flow.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bjx.common.core.domain.R;
import com.bjx.common.core.domain.group.Update;
import com.bjx.flow.domain.query.FlowDesignQuery;
import com.bjx.flow.domain.vo.FlowDesignDeployVO;
import com.bjx.flow.domain.vo.FlowDesignVO;
import com.bjx.flow.service.IFlowDesignService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @desc: 流程设计控制器
 * @author: liushuai
 * @date: 2022/10/24
 */
@RequestMapping("/design")
@Tag(name = "流程设计控制器")
@RestController
public class FlowDesignController {

    @Autowired
    private IFlowDesignService flowDesignService;



    /**
     * 分页查询流程设计列表
     * @param flowDesignQuery
     * @return: R<IPage<FlowDesignVO>>
     * @Author: liushuai
     * @Date: 2022/10/24
     */
    @Operation(summary = "分页查询流程设计列表")
    @GetMapping("listFlowDesignPage")
    public R<IPage<FlowDesignVO>> listFlowDesignPage(FlowDesignQuery flowDesignQuery) {
        IPage<FlowDesignVO> page = flowDesignService.listFlowDesignPage(flowDesignQuery);
        return R.success(page);
    }

    /**
     * 根据流程设计id查询流程设计
     * @param designId
     * @return:R<FlowDesignVO>
     * @Author: liushuai
     * @Date: 2022/10/24
     */
    @Operation(summary = "根据流程设计id查询流程设计")
    @GetMapping("selectFlowDesignByDesignId")
    public R<FlowDesignVO> selectFlowDesignByDesignId(@RequestParam Long designId){
        FlowDesignVO vo = flowDesignService.selectFlowDesignByDesignId(designId);
        return R.success(vo);
    }

    /**
     * 根据流程设计id删除流程设计
     * @param designId
     * @return: R
     * @Author: liushuai
     * @Date: 2022/10/24
     */
    @Operation(summary = "根据流程设计id删除流程设计")
    @GetMapping("deleteFlowDesignByDesignId")
    public R deleteFlowDesignByDesignId(@RequestParam Long designId){
        flowDesignService.deleteFlowDesignByDesignId(designId);
        return R.successMsg("删除流程设计成功");
    }

   /**
    * 新增流程设计
    * @param flowDesignVO
    * @return: R
    * @Author: liushuai
    * @Date: 2022/10/24
    */
   @Operation(summary = "新增流程设计")
   @PostMapping("insertFlowDesign")
   public R insertFlowDesign(@RequestBody @Validated FlowDesignVO flowDesignVO){
      flowDesignService.insertFlowDesign(flowDesignVO);
      return R.successMsg("新增流程设计成功");
   }

    /**
     * 修改流程设计
     * @param flowDesignVO
     * @return: R
     * @Author: liushuai
     * @Date: 2022/10/24
     */
    @Operation(summary = "修改流程设计")
    @PostMapping("updateFlowDesign")
    public R updateFlowDesign(@RequestBody @Validated(Update.class) FlowDesignVO flowDesignVO){
        flowDesignService.updateFlowDesign(flowDesignVO);
        return R.successMsg("修改流程设计成功");
    }

    /**
     * 部署流程设计
     * @param flowDesignDeployVO
     * @return: com.bjx.common.core.domain.R
     * @Author: liushuai
     * @Date: 2022/11/1 11:42
     */
    @Operation(summary = "部署流程设计")
    @PostMapping("deployFlowDesign")
    public R deployFlowDesign(@RequestBody FlowDesignDeployVO flowDesignDeployVO){
        flowDesignService.deployFlowDesign(flowDesignDeployVO);
        return R.successMsg("部署流程设计成功");
    }
}
